<template>

    <div>

        <el-form  :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="工时类型" prop="WorkhoursType">
                <el-select v-model="model.WorkhoursType" placeholder="请选择工时类型">
                    <el-option label="钳工" value="钳工"></el-option>
                    <el-option label="浇筑" value="浇筑"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="工时" prop="Workhours">
                <el-input-number v-model="model.Workhours"></el-input-number>
            </el-form-item>

            <el-form-item label="员工姓名" prop="WorkerName">
                <el-input v-model="model.WorkerName" placeholder="请选择员工" :readonly="true"
                @focus="addBom"></el-input>
            </el-form-item>

            <el-form-item label="所属车间" prop="WorkshopName">
                <el-input v-model="model.WorkshopName"></el-input>
            </el-form-item>

            <el-form-item class="page-box-footer">
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
        
        <!-- 弹窗 -->
        <el-dialog append-to-body :close-on-click-modal="false" :title="dialogDomain.title"
            :visible.sync="dialogDomain.dialogVisible" width="60%" >
            <SelectedEmployees @callback="AddBomCallBack"  v-if="dialogDomain.dialogVisible" />
            
        </el-dialog>


    </div>


</template>

<script>

import SelectedEmployees from './SelectedEmployees.vue';


export default {
    components: {
        SelectedEmployees,
    },
    props:{
        model:{
            require:true,
            type:Object
        },
        isUpdate: {
            required: true,
            type: Boolean
        }
    },
    data(){
        return {

            //对话框对象
            dialogDomain: {
                title: '物料产品选择',
                dialogVisible: false,
            },
            tableData: [],
            UnitMeasureList:[],
            
            rules: {
                WorkhoursType: { required: true, message: '请选择工时类型', trigger: 'blur' },
                Workhours: { required: true, message: '请输入工时', trigger: 'blur' },
                WorkshopName:{required: true, message: '请输入所属车间', trigger: 'blur'},
            }
        }
    },
    created(){
        this.GetProTemporaryWorkHoursAll();
    },
    methods:{
        //添加成员
        addBom() {
            this.dialogDomain.title = "选择成员";
            this.dialogDomain.dialogVisible = true;
        },


        submitForm(){
            this.$refs['ruleForm'].validate((valid)=>{
                if(valid){
                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }
                } else{
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
        },
        resetForm(){
            this.$refs['ruleForm'].resetFields();
        },

        //新增
        add(){
            this.$http.postForm('/api/ProTemporaryWorkHours',{model:this.model},{loading:this.$loading()})
            .then(res=>{
                this.$emit('callback');
            })
        },

        //修改
        put(){
            this.$http.putForm('/api/ProTemporaryWorkHours',{model:this.model},{loading:this.$loading()})
            .then((res)=>{
                this.$emit('callback');
            })
        },

        GetProTemporaryWorkHoursAll(){
        this.$http.get('/api/QcProjectDevice/GetAll')
        .then(res=>{
            this.UnitMeasureList=res.Data ;
        })
        },
        
         //新增或编辑页面回调
         AddBomCallBack(model) {
            console.log(model)
            this.model.WorkerName=model.Name

            this.dialogDomain.dialogVisible = false;
        },
    

    }
    
}

</script>

<style scoped>
    

</style>